﻿using HighThroughput.ShareData;
using Org.BouncyCastle.Asn1.Crmf;
using OSSUtility;
using Ozone.Device;
using Ozone.Help;
using Ozone.Views.Video;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.AppCenter
{
    /// <summary>
    /// UCAppCenterMain.xaml 的交互逻辑
    /// </summary>
    public partial class UCAppCenterMain : UserControl
    {
        private List<Grid> lstTabGridContent = new List<Grid>();
        private List<Border> lstTabButtonGrid = new List<Border>();
        public UCAppCenterMain()
        {
            InitializeComponent();
            Init();
        }
        private void Init()
        {

            //TAB页对应的内容
            lstTabGridContent.Add(gridCenter1);
            lstTabGridContent.Add(gridCenter2);
            lstTabGridContent.Add(gridCenter3);

            //TAB页按钮
            lstTabButtonGrid.Add(gridTab1);
            lstTabButtonGrid.Add(gridTab2);
            lstTabButtonGrid.Add(gridTab3);
            if (!InitCam())
            {
                LogHelper.Info("相机初始化失败");
                return;
            }
            LogHelper.Info("相机初始化成功");
        }
        private bool InitCam()
        {
            DeviceCenter.Entity.uCVideoMonitors = new List<UCVideoMonitor>() { pageVideo.pageVideo1, pageVideo.pageVideo2 };
            if(DeviceCenter.Entity.hKCams.Count< DeviceCenter.Entity.uCVideoMonitors.Count)
                return false;
            for (int i = 0; i < DeviceCenter.Entity.uCVideoMonitors.Count; i++)
            {
                DeviceCenter.Entity.hKCams[i] = new HKCam(DeviceCenter.Entity.VideoIPs[i], DeviceCenter.Entity.VideoPasswords[i],
                    DeviceCenter.Entity.VideoTitles[i], i + 1, DeviceCenter.Entity.uCVideoMonitors[i]);
            }
            return true;
        }

        /// <summary>
        /// 切换Tab页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuText_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string tag = ((Border)sender).Tag.ToString();
            int nIndex = Utility.str2int(tag);
            ChangeTabItem(nIndex);
        }
        private void ChangeTabItem(int nIndex)
        {
            //找到资源 背景色
            var myResourceDictionaryShared = new ResourceDictionary
            {
                Source = new Uri("Resources/Styles/Shared.xaml", UriKind.RelativeOrAbsolute) // 指定样式文件的路径
              //Source = new Uri("Resources/Styles/Expander.xaml", UriKind.RelativeOrAbsolute) // 指定样式文件的路径
            };
            //按钮点击背景色
            SolidColorBrush Brush_PurpleBackColor = myResourceDictionaryShared["Brush_WindowBackColor"] as SolidColorBrush; // 通过key找到指定的样式
            //按钮背景色
            SolidColorBrush Brush_MainBackColor = myResourceDictionaryShared["Brush_MainBackColor"] as SolidColorBrush; // 通过key找到指定的样式
            for (int i = 0; i < lstTabGridContent.Count; i++)
            {
                if (i == nIndex)
                {
                    lstTabButtonGrid[i].Background = Brush_PurpleBackColor;
                    lstTabGridContent[i].Visibility = Visibility.Visible;
                }
                else
                {
                    lstTabButtonGrid[i].Background = Brush_MainBackColor;
                    lstTabGridContent[i].Visibility = Visibility.Hidden;
                }
            }
        }
    }
}
